#include <iostream>
#include <algorithm>

using namespace std;
const int N = 110;
int f[N][N];
int a[N][N];

int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, m;
        scanf("%d %d", &n, &m);
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= m;++j)
            {
                scanf("%d", &a[i][j]);
            }
        }

        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= m; ++j)
            {
                f[i][j] = max(f[i - 1][j], f[i][j - 1]) + a[i][j];
            }
        }
        printf("%d", f[n][m]);
    }
}